import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class TwoButtonsGUI {
	JFrame f;
	JLabel l;
	
	public static void main(String[] args) {
		TwoButtonsGUI g = new TwoButtonsGUI();
		g.go();
	}
	
	public void go() {
		f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JButton lb = new JButton("Change Label");
		lb.addActionListener(new LabelListener());	// this will handle label changing button click
		
		JButton cb = new JButton("Change Circle");
		cb.addActionListener(new ColorListener());	// this will handle color changing button click
		
		l = new JLabel("Label");
		DrawPanel d = new DrawPanel(); 				// DrawPanel is custom-draw control that draw circle with random color each repaint time
		
		f.getContentPane().add(BorderLayout.SOUTH, cb); // BorderLayout gives us ability to align added control ("cb") to one of sides of JFrame
		f.getContentPane().add(BorderLayout.CENTER, d);
		f.getContentPane().add(BorderLayout.EAST, lb);
		f.getContentPane().add(BorderLayout.WEST, l);
		
		f.setSize(480, 320);			// resizing frame
		Dimension sb = Toolkit.getDefaultToolkit().getScreenSize(); // obtaining screen size from awt.Toolkit
		f.setLocation((sb.width - f.getWidth())/2, (sb.height - f.getHeight())/2); // calculating center of screen
		
		f.setVisible(true);
	}
	
	class LabelListener implements ActionListener {	// this listener will handle labelButton click (lb)

		@Override
		public void actionPerformed(ActionEvent e) {
			l.setText("Yahoo!");
		}
		
	}
	
	class ColorListener implements ActionListener {	// this listener will handle colorButton click (cb)

		@Override
		public void actionPerformed(ActionEvent e) {
			f.repaint();
		}
		
	}
	
}
